<?php
class EImageForm extends CWidget {

	var $assets = '';
	var $options = array();
	var $title;
	var $model;
	var $name;

	/**
	 * Initializes the widget.
	 * This method is called by {@link CBaseController::createWidget}
	 * and {@link CBaseController::beginWidget} after the widget's
	 * properties have been initialized.
	 */
	public function init()
	{
		$cs = Yii::app()->clientScript;
		$cs->registerScript(__CLASS__,"
		function deleteImageForm(){
			if(confirm('Вы уверены что хотите удалить это?')){
				$('#del_{$this->id}').val(1);
				$('#_{$this->id} label').after($('#upload_{$this->id}'));
				$('#_{$this->id} table').remove();
			}
		}
		", CClientScript::POS_END);
		
		$default = array(
			'delete'=>true,
			'image'=>$this->model->{$this->name},
		);

		$this->options = array_merge($default, $this->options);

        parent::init();
	}

	/**
	 * Executes the widget.
	 * This method is called by {@link CBaseController::endWidget}.
	 */
	public function run()
	{
		$this->render(__CLASS__, array('id'=>$this->id, 'model'=>$this->model, 'name'=>$this->name, 'title'=>$this->title, 'options'=>$this->options));		
	}
	
	
}
?>